<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			function fun(){
				//1.创建核心对象
				let xhr = new XMLHttpRequest()
				//2.创建请求
				xhr.open("GET","data.txt",true)//true表示异步请求
				//3.发送请求
				xhr.send()
				//4.接受数据,解析,显示在页面上
				xhr.onreadystatechange() = function(){
					if(xhr.readyState == 4 && xhr == 200){
				let  data = xhr.textContent
				document.querySelector("span").textContent = data
				}
				
				let data = xhr.responseText
				document.querySelector("span").textContent = data
			}
		</script>
	</head>
	<body>
		请求到的数据：<span></span>
		<br>
		<button type="button" onclick="fun()">请求数据</button>
	</body>
</html>
